/*
All analyses was done using STATAMP version 17.0
The do file is orgnaized by Figures and Tables that match the sequence in the published paper
*/

//Figure 2

twoway (kdensity refi_num_resw2546, ) (kdensity refi_num_resw2542)


//Figure 3
**# Figure 2: dot plot of most saturated specification 

use "D:\Dropbox\Experian\short_run.dta", replace 

*full granularity
reghdfe fail  $size4 $size9 $size19 $size49 $size99, cluster(state) absorb(fips)

foreach s in sm4 sm9 sm19 sm49 sm99 {
mat `s'=J(6,3,.)
local i 0
foreach v in 2546 2545 2544 2543 2542 2541  {
	local ++i 
	lincom 1.`s'#c.std_refi_amt_resw`v'-0b.`s'#c.std_refi_amt_resw`v'
    matrix `s'[`i',1] = `r(estimate)', `r(t)', `r(p)'
    mat t`s'=`s''
mat2txt , mat(t`s') saving(t`s') format(%9.4f) replace 	
}
}
mat A= tsm4\tsm9\tsm19\tsm49\tsm99
mat colnames A= (-2) (-1) "announcement week" (+1) (+2) (+3)
mat rownames A= "coefficient, <4 employees" "t-statistic, <4 employees" "p-value,<4 employees" "coefficient,4-9 employees" "t-statistic 4-9 employees" "p-value, 4-9 employees" "coefficient,10-19 employees" "t-statistic, 10-19 employees" "p-value, 10-19 employees" "coefficient,20-49 employees" "t-statistic, 20-49 employees" "p-value, 20-49 employees"  "coefficient, 50-99 employees" "t-statistic, 50-99 employees" "p-value, 50-99 employees"
mat2txt , mat(A) saving(A) format(%9.4f) replace 	



foreach s in sm4 sm9 sm19 sm49 sm99 {
mat `s'=J(6,3,.)
local i 0
foreach v in 2546 2545 2544 2543 2542 2541  {
	local ++i 
	lincom 1.`s'#c.std_refi_amt_resw`v'-0b.`s'#c.std_refi_amt_resw`v'
    matrix `s'[`i',1] = `r(estimate)', `r(lb)', `r(ub)'
    *mat t`s'=`s''
*mat2txt , mat(t`s') saving(t`s') format(%9.4f) replace 	
}
}


coefplot (matrix(sm4[,1]), ci((sm4[,2] sm4[,3]))), vertical yline(0) coeflabels( r1="3 weeks before" r2="2 weeks before" r3="1 week before" r4="QE 1 week" r5="1 week after" r6="2 weeks after") xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall))



reghdfe fail  $size4num $size9num $size19num $size49num $size99num, cluster(state) absorb(fips)


foreach s in sm4 sm9 sm19 sm49 sm99 {
mat `s'=J(6,3,.)
local i 0
foreach v in 2541 2542 2543 2544 2545 2546  {
	local ++i 
	lincom 1.`s'#c.std_refi_num_resw`v'-0b.`s'#c.std_refi_num_resw`v'
    matrix `s'[`i',1] = `r(estimate)', `r(lb)', `r(ub)'
    *mat t`s'=`s''
*mat2txt , mat(t`s') saving(t`s') format(%9.4f) replace 	
}
}


coefplot (matrix(sm4[,1]), ci((sm4[,2] sm4[,3]))), vertical yline(0) coeflabels( r1="3 weeks before" r2="2 weeks before" r3="1 week before" r4="QE 1 week" r5="1 week after" r6="2 weeks after") xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("less than 5 employees", size(vsmall))


coefplot (matrix(sm9[,1]), ci((sm9[,2] sm9[,3]))), vertical yline(0) coeflabels( r1="3 weeks before" r2="2 weeks before" r3="1 week before" r4="QE 1 week" r5="1 week after" r6="2 weeks after") xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("5-9 employees", size(vsmall))


coefplot (matrix(sm19[,1]), ci((sm19[,2] sm19[,3]))), vertical yline(0) coeflabels( r1="3 weeks before" r2="2 weeks before" r3="1 week before" r4="QE 1 week" r5="1 week after" r6="2 weeks after") xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("10-19 employees", size(vsmall))


coefplot (matrix(sm49[,1]), ci((sm49[,2] sm49[,3]))), vertical yline(0) coeflabels( r1="3 weeks before" r2="2 weeks before" r3="1 week before" r4="QE 1 week" r5="1 week after" r6="2 weeks after") xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("20-49 employees", size(vsmall))


coefplot (matrix(sm99[,1]), ci((sm99[,2] sm99[,3]))), vertical yline(0) coeflabels( r1="3 weeks before" r2="2 weeks before" r3="1 week before" r4="QE 1 week" r5="1 week after" r6="2 weeks after") xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("50-99 employees", size(vsmall))
*/

//Figure 4 
use "D:\Dropbox\Experian\short_run.dta", replace
merge m:1 fips using D:\Dropbox\Haoyang\data\change_chmda_week_ar1_4.dta, keepusing(post_1 post_2 post_3 post_4 pre_1 pre_2 pre_3 pre_4) nogen 


foreach v in post_2 post_3 post_4 pre_2 pre_3 pre_4 {
	g sm1_`v'=sm1*`v'
	g sm2_`v'=sm2*`v'
}


set more off
cap erase table.txt
cap erase table.xls 

mat sm2post=J(5,3,.)
mat sm1post=J(5,3,.)
mat sm2pre=J(5,3,.)
mat sm1pre=J(5,3,.)





reghdfe fail sm1_post   sm2_post sm1_pre   sm2_pre  sm1 sm2 , absorb(fips) cluster(state)
outreg2 using table.xls, keep(sm1_post   sm2_post sm1_pre   sm2_pre) stats(coef se)  stnum(replace coef=coef*100, replace se=se*100) label nocons 

	
	sum post_num if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_post
    matrix sm2post[1,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_post
    matrix sm1post[1,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	
	sum pre_num if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_pre
    matrix sm2pre[1,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_pre
    matrix sm1pre[1,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'

reghdfe fail sm1_post_2   sm2_post_2 sm1_pre_2   sm2_pre_2  sm1 sm2 , absorb(fips) cluster(state)
outreg2 using table.xls, keep(sm1_post_2   sm2_post_2 sm1_pre_2   sm2_pre_2) stats(coef se)  stnum(replace coef=coef*100, replace se=se*100) label nocons 


	sum post_2 if e(sample),de
	local rsd=(r(p90)-r(p10))
	lincom sm2_post_2
    matrix sm2post[2,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_post_2
    matrix sm1post[2,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	
	sum pre_2 if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_pre_2
    matrix sm2pre[2,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_pre_2
    matrix sm1pre[2,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'

reghdfe fail sm1_post_3   sm2_post_3 sm1_pre_3   sm2_pre_3  sm1 sm2 , absorb(fips) cluster(state)
outreg2 using table.xls, keep(sm1_post_3   sm2_post_3 sm1_pre_3   sm2_pre_3) stats(coef se)  stnum(replace coef=coef*100, replace se=se*100) label nocons 


	sum post_3 if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_post_3
    matrix sm2post[3,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_post_3
    matrix sm1post[3,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	
	sum pre_3 if e(sample),de
	local rsd=(r(p90)-r(p10))
	lincom sm2_pre_3
    matrix sm2pre[3,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_pre_3
    matrix sm1pre[3,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'

reghdfe fail sm1_post_4   sm2_post_4 sm1_pre_4   sm2_pre_4  sm1 sm2 , absorb(fips) cluster(state)
outreg2 using table.xls, keep(sm1_post_4   sm2_post_4 sm1_pre_4   sm2_pre_4) stats(coef se)  stnum(replace coef=coef*100, replace se=se*100) label nocons 

	sum post_4 if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_post_4
    matrix sm2post[4,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_post_4
    matrix sm1post[4,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	
	sum pre_4 if e(sample),de
	local rsd=(r(p90)-r(p10))
	lincom sm2_pre_4
    matrix sm2pre[4,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_pre_4
    matrix sm1pre[4,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	
reghdfe fail sm1_mc587 sm1_mc586 sm2_mc587 sm2_mc586 sm1 sm2  , absorb(fips) cluster(state)
outreg2 using table.xls, keep(sm1_mc587 sm1_mc586 sm2_mc587 sm2_mc586) stats(coef se)  stnum(replace coef=coef*100, replace se=se*100) label nocons 

	sum num_refis_chg_resid587 if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_mc587
    matrix sm2post[5,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_mc587
    matrix sm1post[5,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	
	sum num_refis_chg_resid586  if e(sample), de
	local rsd=(r(p90)-r(p10))
	lincom sm2_mc586
    matrix sm2pre[5,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'
	lincom sm1_mc586
    matrix sm1pre[5,1] = `r(estimate)'*`rsd', `r(lb)'*`rsd', `r(ub)'*`rsd'

mat sm2post=100*sm2post







coefplot (matrix(sm2post[,1]), ci((sm2post[,2] sm2post[,3]))), vertical yline(0) coeflabels( r1="AR(1)" r2="AR(2)" r3="AR(3)" r4="AR(4)" r5="McDash" ) xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit (%)", size(vsmall)) xtitle("Alternative Models", size(vsmall))

mat sm1post=sm1post*100
coefplot (matrix(sm1post[,1]), ci((sm1post[,2] sm1post[,3]))), vertical yline(0) coeflabels( r1="AR(1)" r2="AR(2)" r3="AR(3)" r4="AR(4)" r5="McDash" ) xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("Alternative Models", size(vsmall))

mat sm2pre=100*sm2pre
coefplot (matrix(sm2pre[,1]), ci((sm2pre[,2] sm2pre[,3]))), vertical yline(0) coeflabels( r1="AR(1)" r2="AR(2)" r3="AR(3)" r4="AR(4)" r5="McDash" ) xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("Alternative Models", size(vsmall))

mat sm1pre=100*sm1pre
coefplot (matrix(sm1pre[,1]), ci((sm1pre[,2] sm1pre[,3]))), vertical yline(0) coeflabels( r1="AR(1)" r2="AR(2)" r3="AR(3)" r4="AR(4)" r5="McDash" ) xlabel(,labsize(vsmall)) ylabel(, labsize(vsmall)) ytitle("probability of exit", size(vsmall)) xtitle("Alternative Models", size(vsmall))

//Table 2/3

use D:\Dropbox\Experian\short_run.dta, clear 
keep sic2num
drop if sic2num==.
bysort sic2num: g n=_N
g N=_N
g percent=100*n/N
collapse percent, by(sic2num)
gsort- percent 

**# geographic distribution of businesses 
use D:\Dropbox\Experian\short_run.dta, clear 
keep fips experianbusinessidentificationnu
merge m:1 fips using "C:\Users\rodne\OneDrive - University of Southern California\Banking and Industrial Structure\Banking and Industrial Structure\ICPSR Data\ICPSR_revised_2010\DS0106\02896-0106-Data.dta", keepusing(region1 region2) 
drop if region1==.
bysort region1: g n=_N
g N=_N
g percent=100*n/N
collapse percent, by(region1)


//Table 4
label var refi_num_resw2541 "3 weeks before QE 1"
label var refi_num_resw2542 "2 weeks before QE 1"
label var refi_num_resw2543 "1 week before QE 1"
label var refi_num_resw2544 "week of QE 1 "
label var refi_num_resw2545 "1 week after QE 1"
label var refi_num_resw2546 "2 weeks after QE 1"
label var inc_ln "log median income"
label var popdensity2010 "population density, 2009"
label var percent_white2009 "% white population, 2009"
label var percent_black2009 "% black population, 2009"
label var num_refis_chg_resid584 "refi shock, two months before QE 1"
label var num_refis_chg_resid585 "refi shock, one month before QE 1"
label var num_refis_chg_resid586 "refi shock, month of QE 1"
label var num_refis_chg_resid587 "refi shock, one month after QE 1"
label var num_refis_chg_resid588 "refi shock, two months after QE 1"


foreach v in refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545  refi_num_resw2546 num_refis_chg_resid584 num_refis_chg_resid585  num_refis_chg_resid586 num_refis_chg_resid587 num_refis_chg_resid588 {
	replace `v'=`v'/100
}

set more off 
cap erase table.txt 
cap erase table.xls 



reghdfe refi_pct_2009 refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545  refi_num_resw2546, absorb(state) cluster(state)
outreg2 using table.xls, ctitle("% of mortages refinanced in 2009") label nocons keep(refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545)

reghdfe refi_pct_2009 refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545  refi_num_resw2546 inc_ln, absorb(state) cluster(state)
outreg2 using table.xls, ctitle(""% of mortages refinanced in 2009") label nocons keep(refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545)

reghdfe refi_pct_2009 refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545  refi_num_resw2546  inc_ln popdensity2010 percent_white2009 percent_black2009, absorb(state) cluster(state)
outreg2 using table.xls, ctitle("% of mortages refinanced in 2009") label nocons keep(refi_num_resw2541 refi_num_resw2542 refi_num_resw2543 refi_num_resw2544 refi_num_resw2545)

//Table 5

label var refi_num_resw2541 "3 weeks before QE 1"
label var refi_num_resw2542 "2 weeks before QE 1"
label var refi_num_resw2543 "1 week before QE 1"
label var refi_num_resw2544 "week of QE 1 "
label var refi_num_resw2545 "1 week after QE 1"
label var refi_num_resw2546 "2 weeks after QE 1"
label var post_num "post QE1 shock"
label var pre_num "pre QE1 shock"


set more off 
cap erase table.txt 
cap erase table.xls

reg refi_prin_diff_ag pre_num post_num inc_ln popdensity2010 percent_white2009 percent_black2009 if datem==588 & fips!=48097 & fips!=51830 , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("Principal Savings:January 2009") label nocons keep(pre_num post_num)

reg refi_prin_diff_ag pre_num post_num inc_ln popdensity2010 percent_white2009 percent_black2009 if datem==589 & fips!=48097 & fips!=51830 , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("Principal Savings:Feburary 2009") label nocons keep(pre_num post_num)
predict e if e(sample)

reg refi_prin_diff_ag pre_num post_num inc_ln popdensity2010 percent_white2009 percent_black2009 if datem==590 & fips!=48097 & fips!=51830 , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("Principal Savings:March 2009") label nocons keep(pre_num post_num)

reg sav_ag pre_num post_num inc_ln popdensity2010 percent_white2009 percent_black2009 if datem==588 & fips!=48097 & fips!=51830 , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("Payment Savings:January 2009") label nocons keep(pre_num post_num)

reg sav_ag pre_num post_num inc_ln popdensity2010 percent_white2009 percent_black2009 if datem==589 & fips!=48097 & fips!=51830 , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("Payment Savings:Feburary 2009") label nocons keep(pre_num post_num)

reg sav_ag pre_num post_num inc_ln popdensity2010 percent_white2009 percent_black2009  if datem==590 & fips!=48097 & fips!=51830 , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("Payment Savings:March 2009") label 


//Table 6
set more off 
cap erase table.txt 
cap erase table.xls 


label var inc_ln "log median income, 2009"
label var dl12_county_hpi "average change in house prices, 2008 November-2007 November"
label var unemployment "unemployment rate, November 2008"
label var median_hh_equity_ratio "median home equity ratio,November 2008"
label var underwater_ratio "% of mortgages with negative equity, November 2008"

reg post_num inc_ln if datem==590 & dl12_county_hpi!=. , absorb(state) cluster(state)
sum c.inc_ln if e(sample), de
dis (`r(sd)') *_b[inc_ln]
local imp=(`r(sd)') *_b[inc_ln]
sum post_num if e(sample)
dis `imp'/`r(mean)'
local mar=`imp'/`r(sd)'
outreg2 using table.xls, ctitle("income") adds(impact,`mar') label nocons

reg post_num frac_coll_plus2010 if datem==590 & dl12_county_hpi!=. , absorb(state) cluster(state)
sum c.frac_coll_plus2010 if e(sample), de
dis (`r(sd)') *_b[frac_coll_plus2010]
local imp=(`r(sd)') *_b[frac_coll_plus2010]
sum post_num if e(sample)
dis `imp'/`r(mean)'
local mar=`imp'/`r(sd)'
outreg2 using table.xls, ctitle("college") adds(impact,`mar') label nocons


reg post_num unemployment if datem==590 & dl12_county_hpi!=. , absorb(state) cluster(state)
sum unemployment if e(sample), de
dis (`r(sd)') *_b[unemployment]
local imp=(`r(sd)') *_b[unemployment]
sum post_num if e(sample)
dis `imp'/`r(mean)'
local mar=`imp'/`r(sd)'
outreg2 using table.xls, ctitle("unemployment") adds(impact,`mar') label nocons

reg post_num dl12_county_hpi if datem==590 & dl12_county_hpi!=. , absorb(state) cluster(state)
sum dl12_county_hpi if e(sample), de
dis (`r(sd)') *_b[dl12_county_hpi]
local imp=(`r(sd)') *_b[dl12_county_hpi]
sum post_num if e(sample)
dis `imp'/`r(mean)'
local mar=`imp'/`r(sd)'
outreg2 using table.xls, ctitle("housing") adds(impact,`mar') label nocons


reg post_num median_hh_equity_ratio if datem==590 & dl12_county_hpi!=. , absorb(state) cluster(state)
sum median_hh_equity_ratio if e(sample), de
dis (`r(sd)') *_b[median_hh_equity_ratio]
local imp=(`r(sd)') *_b[median_hh_equity_ratio]
sum post_num if e(sample)
dis `imp'/`r(mean)'
local mar=`imp'/`r(sd)'
outreg2 using table.xls, ctitle("housing") adds(impact,`mar') label nocons

reg post_num underwater_ratio if datem==590 & dl12_county_hpi!=. , absorb(state) cluster(state)
sum underwater_ratio if e(sample), de
dis (`r(sd)') *_b[underwater_ratio]
local imp=(`r(sd)') *_b[underwater_ratio]
sum post_num if e(sample)
dis `imp'/`r(mean)'
local mar=`imp'/`r(sd)'
outreg2 using table.xls, ctitle("housing") adds(impact,`mar') label nocons

reg post_num inc_ln dl12_county_hpi underwater_ratio unemployment median_hh_equity_ratio frac_coll_plus2010 if datem==590  , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("all")  label nocons

reg pre_num inc_ln dl12_county_hpi underwater_ratio unemployment median_hh_equity_ratio frac_coll_plus2010  if datem==590  , absorb(state) cluster(state)
outreg2 using table.xls, ctitle("pre-QE1: all")  label nocons

//Table 7
set more off 
cap erase table.txt 
cap erase table.xls 


*non-linear specification
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2   if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("baseline") keep(sm1_pdum3 sm2_pdum3 sm1_inc sm2_inc) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*add income
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2 sm1_inc sm2_inc  if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("baseline") keep(sm1_pdum3 sm2_pdum3 sm1_inc sm2_inc) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

/*
foreach v in  unemployment {
	g sm1_`v'=sm1*`v'
	g sm2_`v'=sm2*`v'
}
*/

*add unemployment 
reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_unemployment sm2_unemployment if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("baseline") keep(sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc sm1_unemployment sm2_unemployment) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


*6 month change in construction employment
reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_dl6_cons_employment sm2_dl6_cons_employment if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and construction employment slope terms") keep(sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc sm1_dl6_cons_employment sm2_dl6_cons_employment) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


*underwater ratio
reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc  sm1_underwater_ratio sm2_underwater_ratio if  dum!=2 , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and negative equity slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre sm1_inc sm2_inc sm1_underwater_ratio sm2_underwater_ratio) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*median home equity
reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_median_hh_equity_ratio sm2_median_hh_equity_ratio if  dum!=2 , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and median home equity slope terms") keep(sm1_pdum3 sm2_pdum3 sm1_inc sm2_inc sm1_median_hh_equity_ratio sm2_median_hh_equity_ratio) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*change in house prices 
reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_dl6_county_hpi sm2_dl6_county_hpi sm1_df6_county_hpi sm2_df6_county_hpi if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and house price slope terms") keep(sm1_pdum3 sm2_pdum3 sm1_inc sm2_inc sm1_dl12_county_hpi sm2_dl6_county_hpi sm1_df6_county_hpi sm2_df6_county_hpi) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


*Saiz Index and house price expectations
reghdfe fail sm1_pdum3 sm2_pdum3 sm2_pre sm1 sm2 sm1_inc sm2_inc sm2_saiz_land_unavailable sm1_saiz_land_unavailable if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and house price expectations slope terms") keep(sm1_pdum3 sm2_pdum3 sm1_inc sm2_inc sm2_saiz_land_unavailable sm1_saiz_land_unavailable) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

/*
**# Documenting the refi channel  
merge m:1 fips using D:\Dropbox\Experian\jan_09_debt_saving.dta, nogen  //"summary_stats_mortgage.do"

foreach v in  sav_ag_587 sav_ag_588 sav_ag_589 sav_ag_590 sav_qe1 sav_ag_avg  refi_prin_diff_ag_587 refi_prin_diff_ag_588 refi_prin_diff_ag_589 refi_prin_diff_ag_590 refi_prin_diff_ag_avg prin_qe1 sav_tax_587 sav_tax_588 sav_tax_589 sav_tax_590 sav_tax_avg  refi_prin_diff_tax_587 refi_prin_diff_tax_588 refi_prin_diff_tax_589 refi_prin_diff_tax_590 refi_prin_diff_tax_avg{
	g sm1_`v'=sm1*`v'
	g sm2_`v'=sm2*`v'
}

foreach v in  sav_ag_avg  refi_prin_diff_ag_avg {
	reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_`v' sm2_`v' if  dum!=2, absorb(fips) cluster(state)
}

foreach v in  refi_prin_diff_ag_587 refi_prin_diff_ag_588 refi_prin_diff_ag_589 refi_prin_diff_ag_590  refi_prin_diff_ag_avg {
	reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_`v' sm2_`v' if  dum!=2, absorb(fips) cluster(state)
}


foreach v in  sav_ag_avg   {
	reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_`v' sm2_`v' , absorb(fips) cluster(state)
}
*/
*Jan 2009 

reghdfe fail sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_refi_prin_diff_ag_587 sm2_refi_prin_diff_ag_587 if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("baseline: Jan 2009 Refinancing Principal Savings") keep(sm1_pdum3 sm2_pdum3 sm1 sm2 sm1_inc sm2_inc sm1_refi_prin_diff_ag_587 sm2_refi_prin_diff_ag_587) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


//Table: Appendix 
set more off 
cap erase table.txt 
cap erase table.xls 

*add median income 
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("baseline: county fixed effects and income slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*add unemployment 
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_unemployment sm2_unemployment, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and unemployment slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*6 month change in construction employment
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_dl6_cons_employment sm2_dl6_cons_employment, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and 6 month change in construction employment slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*12 month change in construction employment
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_dl12_cons_employment sm2_dl12_cons_employment, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and 12 month change in construction employment slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*3 month change in construction employment
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_dl3_cons_employment sm2_dl3_cons_employment, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and 3 month change in construction employment slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)


*underwater ratio
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_underwater_ratio sm2_underwater_ratio  , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and negative equity slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*median home equity
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_median_hh_equity_ratio sm2_median_hh_equity_ratio  , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and median home equity slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre sm1_inc sm2_inc sm1_median_hh_equity_ratio sm2_median_hh_equity_ratio) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*6 month change in house prices 
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_dl6_county_hpi sm2_dl6_county_hpi sm1_df6_county_hpi sm2_df6_county_hpi  , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and 6 month change house price slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)



*12 month change in house prices 
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_dl12_county_hpi sm2_dl12_county_hpi sm1_df12_county_hpi sm2_df12_county_hpi  , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and 12 month change house price slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)

*3 month change in house prices 
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm1_dl3_county_hpi sm2_dl3_county_hpi sm1_df3_county_hpi sm2_df3_county_hpi  , absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and 6 month change house price slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)


*Saiz Index and house price expectations
reghdfe fail sm1_post sm1_pre  sm2_post sm2_pre sm1 sm2 sm1_inc sm2_inc sm2_saiz_land_unavailable sm1_saiz_land_unavailable, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("income and house price expectations slope terms") keep(sm1_post sm1_pre sm2_post sm2_pre) label nocons stats(coef se) stnum(replace coef=coef*1000, replace se=se*1000)


//Table 8: Business Heterogeneity
use "D:\Dropbox\Experian\short_run.dta", replace

label var sm1_pdum3 "less than 20 employees*top tercile post QE1 shock"
label var sm2_pdum3 "20-50 employees*top tercile post QE1 shock"




set more off 
cap erase table.txt 
cap erase table.xls 


*retail
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if ret==1 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("HMDA retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*food
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if food==1 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("HMDA Food") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*manufacturing
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if man==1 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("Manufacturing") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*illiquid businesses
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if hb_mask==1 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("Illiquidity") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*liquid business
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if hb_mask==0 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("Liqudity") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*credit score
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if intelliscoreplusv2score<11 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("High Risk") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if intelliscoreplusv2score>75 & dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("Low Risk") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


//Table 9 
**************************************
label var sm1_pdum3 "less than 20 employees*top tercile post QE1 shock"
label var sm2_pdum3 "20-50 employees*top tercile post QE1 shock"

set more off
cap erase table.txt 
cap erase table.xls

reghdfe hb_mask sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  pdum2!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("full sample") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

reghdfe hb_mask sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  pdum2!=2 & ret==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

reghdfe hb_mask sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  pdum2!=2 & food==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("food") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

reghdfe down sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  pdum2!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("full sample") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

reghdfe down sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  pdum2!=2 & ret==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

reghdfe down sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  pdum2!=2 & food==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("food") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

//Table 10
set more off
cap erase table.txt 
cap erase table.xls 

label var sm1_pdum3 "less than 20 employees*top tercile post QE1 shock"
label var sm2_pdum3 "20-50 employees*top tercile post QE1 shock"



reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("full sample") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & ret==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & food==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("food") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & hb_mask==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("illiquidity: all") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

/*
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & hb_mask==0, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("liquidity: all") keep(sm1_pdum3 sm2_pdum3 ) label 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & ret==1 & hb_mask==0, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("liquidity: retail") keep(sm1_pdum3 sm2_pdum3 ) label 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & food==1 & hb_mask==0, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("liquidity: food") keep(sm1_pdum3 sm2_pdum3 ) label 
*/
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & ret==1 & hb_mask==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("illiquidity: retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & food==1 & hb_mask==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("illiquidity: food") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 

//Table 11
**# Age and Size

set more off
cap erase table.txt 
cap erase table.xls 


reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & monthsinfile<25, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("younger: all") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 
 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & monthsinfile>25, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("older: all") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 


reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & ret==1 & monthsinfile<25, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("younger: retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 
 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc if  dum!=2 & ret==1 & monthsinfile>25, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("older: retail") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100) 



//Table 12
**#Robutness

*merge in American Recovery Act data on fiscal spending 

merge m:1 fips using "D:\Dropbox\Haoyang\data\fips_macro_data.dta", nogen keepusing(recovery_per_capita)


************
***********
*Robutness
*check whether results are coming from banking sector 
set more off
cap erase table.txt 
cap erase table.xls 

****see below for where variables are merged in
foreach v in sm1 sm2 {
	g `v'_pctrefi=`v'*refi_pct_2009
	g `v'_rpc=`v'*recovery_per_capita
}
label var sm1_pctrefi "less than 20 employees*% of mortgages refinanced in 2009"
label var sm2_pctrefi "20-50 employees*% of mortgages refinanced in 2009"
label var sm1_int "less than 20 employees*average mortgage rate difference"
label var sm2_int "20-50 employees*average mortgage rate difference"
label var sm1_pdum3 "less than 20 employees*top tercile post QE1 shock"
label var sm2_pdum3 "20-50 employees*top tercile post QE1 shock"


*deposits
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc i.sm1#c.MBSTAMeanPreQE1_DEP i.sm1#c.MBSTAMeanPreQE2_DEP i.sm1#c.MBSTAMeanPreQE3_DEP i.sm2#c.MBSTAMeanPreQE1_DEP i.sm2#c.MBSTAMeanPreQE2_DEP i.sm2#c.MBSTAMeanPreQE3_DEP  if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("MBS/Assets county exposure") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


*sbl
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc i.sm1#c.MBSTAMeanPreQE1_SBL i.sm1#c.MBSTAMeanPreQE2_SBL i.sm1#c.MBSTAMeanPreQE3_SBL i.sm2#c.MBSTAMeanPreQE1_SBL i.sm2#c.MBSTAMeanPreQE2_SBL i.sm2#c.MBSTAMeanPreQE3_SBL  if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("MBS/Assets county exposure") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*other qe shocks
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc i.sm1#c.post_qe2 i.sm2#c.post_qe2 i.sm1#c.post_qe3 i.sm2#c.post_qe3 if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("QE2 & QE3") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

*fiscal policy
reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc sm1_rpc sm2_rpc if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("American Recovery Act") keep(sm1_pdum3 sm2_pdum3 ) label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

//Table 13


g sole1=sole 
replace sole1=1 if businesstypedmo003==""

foreach v in sm1_pdum3 sm2_pdum3 pdum3 sm1 sm2 {
	g `v'_sole1=`v'*sole1
}
xtile tdum = hpa2015_2010, nq(3)
tab tdum, g(hdum)

g hpa2015_2010_sole1=sole1*hpa2015_2010 

foreach v in pdum2 hdum3 hdum2 {
	g `v'_sole1=`v'*sole1 
}

foreach v in sm1 sm2 {
	g hpa_`v'=hpa2015_2010*`v'
}

label var sm1_pdum3 "less than 20 employees*top tercile post QE1 shock"
label var sm2_pdum3 "20-50 employees*top tercile post QE1 shock"
label var sm1_pdum3_sole1 "less than 20 employees*top tercile post QE1 shock*sole proprietorship"
label var sm2_pdum3_sole1 "20-50 employees*top tercile post QE1 shock*sole proprietorship"
label var pdum3_sole1 "top tercile post QE1 shock*sole proprietorship"
label var pdum2_sole1 "second tercile post QE1 shock*sole proprietorship"
label var hpa2015_2010_sole1 "change in house prices*sole proprietorship"
label var hdum3_sole1 "top tercile house price growth*sole proprietorship" 
label var hdum2_sole1 "second tercile house price growth*sole proprietorship" 
label var hpa_sm1 "less than 20 employees*mean house price growth, 2010-2015"
label var hpa_sm2 "20-50 employees*mean house price growth, 2010-2015"



set more off 
cap erase table.xls
cap erase table.txt


reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc hpa_sm1 hpa_sm2 if  dum!=2, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("house price growth") keep(sm1_pdum3 sm2_pdum3 hpa_sm1 hpa_sm2)  label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)
 

reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc hpa_sm1 hpa_sm2 if  dum!=2 & sole1==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("sole proprietorship") keep(sm1_pdum3 sm2_pdum3 hpa_sm1 hpa_sm2)  label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc hpa_sm1 hpa_sm2 if sole1==1, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("sole proprietorship") keep(sm1_pdum3 sm2_pdum3 hpa_sm1 hpa_sm2)  label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)


reghdfe fail sm1_pdum3 sm2_pdum3  sm1 sm2  sm1_inc sm2_inc hpa_sm1 hpa_sm2 if sole1==1 & monthsinfile<45, absorb(fips) cluster(state)
outreg2 using table.xls, ctitle("sole proprietorship and young businesses") keep(sm1_pdum3 sm2_pdum3 hpa_sm1 hpa_sm2)  label nocons stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

//Table 14
set more off 
cap erase table.txt 
cap erase table.xls 


*impact of refinancings on the change in retail intensity
reghdfe win_loc_ret_chg    refi_pct_2009   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) 
outreg2 using table.xls, ctitle("OLS: retail intensity") label keep(refi_pct_2009) nocons

ivreghdfe win_loc_ret_chg    (refi_pct_2009=pdum3)   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) first
g sam=1 if e(sample)
outreg2 using table.xls, ctitle("IV: retail intensity") label keep(refi_pct_2009) adds("Wald F-statistic", `e(widstat)') nocons

*reduced form 
reg win_loc_ret_chg    pdum3   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 if pdum2!=1 & fips!=21077 & fips!=29075 & fips!=48065 & fips!=4001 & fips!=32029 & sam==1 [aw=pop2010] , absorb(state) cluster(state) 


reghdfe sm1_ret_per refi_pct_2009  median_income2009_ln pop2010_ln percent_white2009 percent_black2009  if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) 
outreg2 using table.xls, ctitle("OLS: small retail") label keep(refi_pct_2009)  nocons

ivreghdfe sm1_ret_per    (refi_pct_2009=pdum3)   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) first
outreg2 using table.xls, ctitle("IV: small retail") label keep(refi_pct_2009) adds("Wald F-statistic", `e(widstat)') nocons

reg sm1_ret_per pdum3  median_income2009_ln pop2010_ln percent_white2009 percent_black2009  if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) 



reghdfe e_ret_2015_pop   refi_pct_2009  median_income2009_ln pop2010_ln percent_white2009 percent_black2009 e_all_2015_ln if pdum2!=1 & sam==1 [aw=pop2010], absorb(state) cluster(state) 
outreg2 using table.xls, ctitle("OLS: retail entry") label keep(refi_pct_2009) nocons

ivreghdfe e_ret_2015_pop    (refi_pct_2009=pdum3)   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 e_all_2015_ln if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) first
outreg2 using table.xls, ctitle("IV: retail entry") label keep(refi_pct_2009) nocons


reg e_ret_2015_pop pdum3  median_income2009_ln pop2010_ln percent_white2009 percent_black2009  if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) 



*impact of refinancings on retail entry intensity 
reghdfe win_e_ret_2015_shy   refi_pct_2009   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 e_all_2015_ln if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) 
outreg2 using table.xls, ctitle("OLS: retail entry") label keep(refi_pct_2009) nocons

ivreghdfe win_e_ret_2015_shy   (refi_pct_2009=pdum3)   median_income2009_ln pop2010_ln percent_white2009 percent_black2009 e_all_2015_ln if pdum2!=1 [aw=pop2010], absorb(state) cluster(state) first
outreg2 using table.xls, ctitle("IV: retail entry") label keep(refi_pct_2009) adds("Wald F-statistic", `e(widstat)') nocons



//Table 15
set more off 
cap erase table.txt 
cap erase table.xls 

reghdfe dol_ln i.post##i.pdum1 if  year>2007, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("full sample") label nocons 

sum fstores_fail_shy if e(sample), de 
sum ret_fail_shy if e(sample), de
sum food_fail_shy if e(sample), de


reghdfe dol_ln i.post##i.pdum1 if   year>2007 & ret_fail_shy>0.28, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("ret_fail_shy>0.28")  label nocons 

reghdfe dol_ln i.post##i.pdum1 if  year>2007 & ret_fail_shy<0.28, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("ret_fail_shy<0.28")  label nocons 

reghdfe dol_ln i.post##i.pdum1 if year>2007 & food_fail_shy>0.24, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("food_fail_shy>0.24")  label nocons 

reghdfe dol_ln i.post##i.pdum1 if  year>2007 & food_fail_shy<0.24, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("food_fail_shy<0.24")  label nocons 

reghdfe dol_ln i.post##i.pdum1 if year>2007 & fstores_fail_shy>0.27, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("fstores_fail_shy>0.27")  label nocons 

reghdfe dol_ln i.post##i.pdum1 if  year>2007 & fstores_fail_shy<0.27, absorb(fips year month) cluster(state)
outreg2 using table.xls, ctitle("stores_fail_shy<0.27")  label nocons 





